package com.gaomall.seckill.exception;

import com.gaomall.seckill.utils.ResultVOUtil;
import com.gaomall.seckill.vo.ResultVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局异常处理
 * extends   RuntimeException ???
 */
@ControllerAdvice
public class GlobleExceptionHandler {

    @ExceptionHandler(value = RestExcepion.class)
    @ResponseStatus(HttpStatus.FORBIDDEN) //403
    public void handlerRestExcepion(){

    }

    @ExceptionHandler(value = CommonException.class)
    @ResponseBody
    public ResultVO handlerCommonException(CommonException e){

        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

    /**
     * 商品服务异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = GoodsException.class)
    @ResponseBody
    public ResultVO handlerGoodsException(GoodsException e){

        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

}
